#define _CRT_SECURE_NO_WARNINGS 

#include <vector>
#include <string>
#include <unordered_map>

using namespace std;

class Solution {
public:
    vector<string> letterCombinations(string digits) {
        vector<string> combinations;
        if (digits.empty())
        {
            return combinations;
        }
        unordered_map<char, string> phoneMap{
            {'2', "abc"},
            {'3', "def"},
            {'4', "ghi"},
            {'5', "jkl"},
            {'6', "mno"},
            {'7', "pqrs"},
            {'8', "tuv"},
            {'9', "wxyz"}
        };
        string combination;
        backtrack(combinations, phoneMap, digits, 0, combination);
        return combinations;
    }

    void backtrack(vector<string>& combinations, const unordered_map<char, string>& phoneMap, const string& digits, int index, string& combination) {
        if (index == digits.length())
        {
            combinations.push_back(combination);
        }
        else
        {
            char digit = digits[index];
            const string& letters = phoneMap.at(digit);
            for (const char& letter : letters)// a b c
            {
                combination.push_back(letter);
                backtrack(combinations, phoneMap, digits, index + 1, combination);// d e f
                combination.pop_back();
            }
        }
    }
};

int main()
{
    Solution s;
    s.letterCombinations("23");
	return 0;
}